//
// Created by root on 12/2/22.
//

#include "MultiplePersonMmPose.h"

MultiplePersonMmPose::MultiplePersonMmPose(const YAML::Node &config){
    pose= new  mmpose(config);
    pose->LoadEngine();
}
/**
 * Inference multiple person from object detection result
 * @param detectSingleImageResults
 * @return
 */
std::vector<MultiplePersonMmPoseResult> MultiplePersonMmPose::inference(std::vector<DetectSingleImageResult> &detectSingleImageResults){

    std::vector<MultiplePersonMmPoseResult>  multiplePersonMmPoseResults=std::vector<MultiplePersonMmPoseResult>();

    for (int i = 0; i < (int)detectSingleImageResults.size(); i++) {

        DetectSingleImageResult detectSingleImageResult=detectSingleImageResults[i];

        std::vector<DetectedObjectItem> detectedObjectItems=detectSingleImageResult.detectedObjectItems;

        MultiplePersonMmPoseResult multiplePersonMmPoseResult;

        std::vector<mmposeRes> mmPoseResult=std::vector<mmposeRes>();

        for(int j=0;j<(int)detectedObjectItems.size();j++){

            DetectedObjectItem detectedObjectItem=detectedObjectItems[j];

            std::vector<cv::Mat> batchPoseInputMat(1);

            batchPoseInputMat[0]=detectedObjectItem.detectedObjectImage;

            std::vector<mmposeRes> singlePoseResult= pose->InferenceImages(batchPoseInputMat);

            mmPoseResult.push_back(singlePoseResult[0]);

            pose->DrawResults(singlePoseResult, batchPoseInputMat);
        }

         multiplePersonMmPoseResult.mmPoseResult=mmPoseResult;
    }

    return multiplePersonMmPoseResults;
}